import {
  homeIndex,
  bestList,
  hotList
} from '@/api/home'
import utils from '@/utils/common'
var timeStamp = Number(new Date())
const home = {
  state: {},

  mutations: {},

  actions: {
    // 首页
    HomeIndex ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp
      }
      return new Promise((resolve, reject) => {
        homeIndex(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 最佳类别
    BestList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        firstTypeId: data.firstTypeId,
        page: data.page,
        pageSize: data.pageSize
      }
      return new Promise((resolve, reject) => {
        bestList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    },
    // 热门
    HotList ({
      getters
    }, data) {
      const loginParams = {
        token: utils.AuthToken(timeStamp, getters.userKey),
        adminId: getters.adminId,
        timestamp: timeStamp,
        type: data.type,
        page: data.page,
        pageSize: data.pageSize || ''
      }
      return new Promise((resolve, reject) => {
        hotList(loginParams).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
        })
      })
    }

  }
}

export default home
